#define _CRT_SECURE_NO_WARNINGS
#include"stack.h"
void STInit(ST* ps)
{
	assert(ps);
	ps->a = NULL;
	ps->capacity = ps->top = 0;
}
void STDestroy(ST* ps)
{
	assert(ps);
	if (ps->a)
	{
		free(ps->a);
		ps->a = NULL;
	}
	ps->capacity = ps->top = 0;
}
void STPush(ST* ps, STDataType x)
{
	assert(ps);
	if (ps->capacity == ps->top)
	{
		int time = ps->capacity == 0 ? 4 : 2 * ps->capacity;
		STDataType* arr = (STDataType*)realloc(ps->a, sizeof(STDataType) * time);
		if (arr == NULL)
		{
			perror("realloc arr");
			return 0;
		}
		ps->a = arr;
		ps->capacity = time;
	}
	ps->a[ps->top++] = x;
}
void STPop(ST* ps)
{
	assert(ps&&ps->top);
	ps->top--;
}
STDataType STTop(ST* ps)
{
	assert(ps && ps->top);
	return ps->a[ps->top - 1];
}
int STSize(ST* ps)
{
	assert(ps);
	return ps->top;
}
bool STEmpty(ST* ps)
{
	assert(ps);
	return ps->top == 0;
}